<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mpChannelMethod-add">
			<input type="hidden" id="channelId" name="channelId" th:value="${mpChannel.id}">
			<div class="form-group">	
				<label class="col-sm-3 control-label">支付类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="payKindId" name="payKindId">
						<option value="" selected>----请选择----</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">钱包类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="walletKindId" name="walletKindId">
						<option value="" selected>----请选择----</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">支付费率：</label>
				<div class="col-sm-8">
					<input id="payRate" name="payRate" class="form-control" type="text" placeholder="0.0001" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户支付方法-费率：</label>
				<div class="col-sm-8">
					<input id="merchantPayRate" name="merchantPayRate" class="form-control" type="text" placeholder="0.0001" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">支付限额(元)：</label>
				<div class="col-sm-3" style="display:inline">
					<input id="payLimitLeft" name="payLimitLeft" class="form-control" type="text"  required>
				</div>
				<div style="display:inline;margin-left: -1%;margin-top: 1%;position: absolute;">
					<span>—</span>
				</div>
				<div class="col-sm-3">
					<input id="payLimitRight" name="payLimitRight" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="false" class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
        var prefix = ctx + "channel/method";
        $("#form-mpChannelMethod-add").find("input[name='withdrawalLevel']").val(1);

		/*支付类型标识下拉框 */
        $.post(ctx + "basedata/paykind/list", {},function (response) {
            var data = response.rows;
            var option = "";
            for (var i = 0; i < data.length; i++) {
                option += "<option value='"+ data[i].id +"'>" + data[i].name + "</option>"
            }
            $("#form-mpChannelMethod-add").find("select[name='payKindId']").html("").append(option);
        });

        /*钱包类型标识下拉框*/
        $.post(ctx + "basedata/walletkind/list", {},function (response) {
            var data = response.rows;
            var option = "";
            for (var i = 0; i < data.length; i++) {
                option += "<option value='"+ data[i].id +"'>" + data[i].name + "</option>"
            }
            $("#form-mpChannelMethod-add").find("select[name='walletKindId']").html("").append(option);
        });


        $.validator.addMethod("regex",function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        },"请输入数字(可保留两位小数)");
        $.validator.addMethod("regex2",function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        },"小于1(可保留四位小数)");
        $.validator.addMethod("NoZero",function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        },"不能为零");
		/*规则校验*/
		$("#form-mpChannelMethod-add").validate({
			rules:{
                payRate:{
                    regex2:"^[0]+(.[0-9]{4}|.[0-9]{3}|.[0-9]{2}|.[0-9]{1})?$"
				},
                merchantPayRate:{
                    regex2:"^[0]+(.[0-9]{4}|.[0-9]{3}|.[0-9]{2}|.[0-9]{1})?$"
                },
                payLimitLeft:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                },
                payLimitRight:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                }
			},
			focusCleanup: true
		});

		/*提交表单*/
		function submitHandler() {
	        if ($.validate.form()) {
                var data = $("#form-mpChannelMethod-add").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                if (status != 0){
                    data.push({"name": "status", "value": status});
                } else {
                    data[7].value = status;
                }
                // 支付限额左
                data[5].value = new Decimal(data[5].value).mul(new Decimal(100));
				// 支付限额右
                data[6].value = new Decimal(data[6].value).mul(new Decimal(100));
                $.operate.save(prefix + "/addMethod", data);
	        }
	    }
	</script>
</body>
</html>
